<% if @photo_set %>
  <% content_for(:head) do %>
    <script type="text/javascript" charset="utf-8">/*<![CDATA[*/
      Event.observe(window, 'load', function() {
        var table = $('photos-list');
        if (table) {
          var dnd = new TableDnD();
          dnd.init(table);
          dnd.onDrop = Admin.reorderPhotoSet;
        }
      });
    /*]]>*/</script>
  <% end %>
<% end %>

<div class="admin photos">
  <div class="section header dark-50">
    <h2 class="light"><%= @photo_set ? "Edit" : "Add" %> Photos</h2>
  </div>
  
  <div class="entry">
    <% form_remote_tag(
        :url => { 
          :action     => "photos_submit" },
        :complete => 
          "Submit.genericAfterSubmit",
        :before => "Submit.genericSubmit();"
        ) do %>
      <div class="top">
        <%= text_field_tag(
              "photo_set_name", 
              @photo_set ? @photo_set.name : "Photo Set Name", 
              :class => "default photo_set_name #{"dormant" if !@photo_set}",
              :autocomplete => "off") %>
        <%= hidden_field_tag(
              "photo_set_id", 
              @photo_set ? @photo_set.id : nil) %>
      </div>
      <div class="main">
        <div>
          <%= default_text_field_tag("photo_set", "caption", @photo_set) %>
          <br/><br/>
        </div>
        <div id="photos-list">
          <%#
              <div id="photo_upload_SWFUpload_0_0" class="photo_upload">
                <div class="photo_upload_placeholder"> </div>
                <div class="photo_upload_info">
                  <div class="photo_upload_name">1.jpg</div>
                  <div class="photo_upload_status">Waiting...</div>
                </div>
                <br class="clear"/>
              </div>
          %>
          
          <% if @photo_set %>
            <% @photo_set.photos.each do |photo| %>
              <div class="photo_upload activatable row" id="photo_container_<%= photo.id %>">
                <%= hidden_field_tag(
                      "position_for_#{photo.id}", 
                      "#{photo.position}",
                      { :class => "position" } ) %>
                <div class="photo_upload_hide hideable">
                  <%= link_to_remote(
                    "x", 
                    :url => { 
                      :controller => "admin", 
                      :action     => "hide",
                      :id         => photo.id,
                      :type       => "Photo",
                      :published  => 0 } ) %>
                </div>
                <div class="photo_upload_placeholder">
                  <%= display_photo(photo, true, @photo_set) %>
                </div>
                <div class="photo_upload_info">
                  <div class="photo_upload_name">
                    <%= photo.path %>
                  </div>
                  <div class="photo_upload_status">
                    <%= text_field_tag(
                          "caption_for_#{photo.id}", 
                          photo.caption, 
                          :class => "default",
                          :autocomplete => "off") %>
                  </div>
                </div>
                <br class="clear"/>
              </div>
            <% end %>
          <% end %>
          
        </div>  
      </div>
      <div class="bottom">
        <div class="submit">
          <%= submit_tag "Save", :class => "default submit" %>  
        </div>
        <div>
          <span id="swfu-holder"></span>
          <span id="upload_status"></span>
        </div>
      </div>
    <% end %>
  </div>
  <br/>
  
  <div class="section header dark-50">
    <h2 class="light">Recent Photo Sets</h2>
  </div>
  <div class="section body dark-25">
    <% @photo_sets.each do |photo_set| %> 
      <%= link_to( h(photo_set.name), admin_photos_edit_url(:id => photo_set.id, :type => photo_set.class.to_s) ) %>
      <br/>
    <% end %>
  </div>
</div>